package com.admin.client.controller.gm;

import com.comment.dubbo.service.PlayerService;
import com.comment.dubbo.service.SystemEmailsService;
import com.comment.dubbo.service.bag.BagItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.*;

@Api(tags = "gm指令")
@Validated
@RestController
@RequestMapping("/gmAction")
public class GMAction {
    @DubboReference
    BagItemService bagItemService;
    @DubboReference
    SystemEmailsService systemEmailsService;
    @DubboReference
    PlayerService playerService;

    @ApiOperation("给玩家发物品")
    @GetMapping("/obtainBagItem")
    public boolean obtainBagItem(Long playerId, Long corePropId, BigDecimal obtainNum) {
        return bagItemService.obtainBagItem(playerId, corePropId, obtainNum);
    }

    @ApiOperation("给全服玩家发物品")
    @GetMapping("/obtainBagItemAll")
    public boolean obtainBagItemAll(Long corePropId, BigDecimal obtainNum) {
        return bagItemService.obtainBagItemAll(corePropId, obtainNum);
    }

    @ApiOperation("给全服玩家发邮件")
    @GetMapping("/sendEmail")
    public boolean obtainBagItemAll(
            String title,
            String content,
            Integer expirationDay,
            Long corePropId,
            BigDecimal obtainNum
    ) {
        Map<String, Object> attachment = new HashMap<>();
        Map<Long, Long> hashMap = new HashMap<>();
        hashMap.put(corePropId, obtainNum.longValue());
        attachment.put("prop", hashMap);

        Set<Long> playerIds = playerService.obtainPlayerIds();
        ArrayList<Long> longs = new ArrayList<>(playerIds);
        return systemEmailsService.sendEmail(title, content, expirationDay, longs, attachment);
    }
}
